home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Personal Computer World 2009 February
/
PCWFEB09.iso
/
Software
/
Resources
/
Burning & Media
/
GB-PVR 1.2.13
/
GBPVR10213.msi
/
Cabs.w1.cab
/
Player2.aspx.cs459
< prev
next >
Wrap
Text File
|
2007-11-24
|
49KB
|
1,175 lines
using System;
using System.Globalization;
using System.IO;
using System.Web;
using System.Web.UI;
using GBPVR.Public;
using GBPVRSchedule;
using gbweb.classes;
namespace gbweb
{
public partial class Player2 : Page
{
private Settings guideParams;
private string serverAddr;
private int vlcProfile;
private System.Diagnostics.Process proc;
private System.Diagnostics.ProcessStartInfo psi;
protected void Page_Load(object sender, EventArgs e)
{
getTheme();
vlcProfile = GetVlcProfile();
//Load settings
guideParams = Global.Settings;
if (!IsPostBack)
{
playerOptions.Visible = true;
MusicVideoControls.Visible = false;
if (Request.Params["type"] == null)
{
if (vlcProfile == 1)
{
SETTINGS_HEADER.InnerHtml = "Player Options - Video Library";
}
else
{
SETTINGS_HEADER.InnerHtml = "Player Options - Music Library";
}
}
else
{
if (Request.Params["type"] == "sn")
{
SETTINGS_HEADER.InnerHtml = "Player Options - Stream Now";
}
else
{
SETTINGS_HEADER.InnerHtml = "Player Options - Manage Recordings";
}
}
transcodeOptions.Visible = false;
resetButton_Click(null, null);
}
//This checks to see if the user clicked on a VLC server control button
if (Request.Form["__EVENTTARGET"] != null)
{
if (Request.Form["__EVENTTARGET"].IndexOf("previousStream") != -1) previousStream(null, null);
if (Request.Form["__EVENTTARGET"].IndexOf("skipBackwardStream") != -1) skipBackwardStream(null, null);
if (Request.Form["__EVENTTARGET"].IndexOf("stopStream") != -1) stopStream(null, null);
if (Request.Form["__EVENTTARGET"].IndexOf("playStream") != -1) playStream(null, null);
if (Request.Form["__EVENTTARGET"].IndexOf("pauseStream") != -1) pauseStream(null, null);
if (Request.Form["__EVENTTARGET"].IndexOf("skipForwardStream") != -1) skipForwardStream(null, null);
if (Request.Form["__EVENTTARGET"].IndexOf("nextStream") != -1) nextStream(null, null);
}
else
{
if ((Request.Params["mvid"] == null) && (Request.Params["mid"] == null) && (Request.Params["type"] == null))
{
streamButton.Visible = false;
}
}
}
private void AddKeepAlive()
{
//Routine to keep session alive
int int_MilliSecondsTimeOut = (Session.Timeout * 60000) - 30000;
string str_Script = @"
<script type='text/javascript'>
//Number of Reconnects
var count=0;
//Maximum reconnects setting
var max = 5;
window.status = 'Auto Reconnect Script is Activated'
function Reconnect(){
count++;
if (count < max)
{
window.status = 'Link to Server Refreshed ' + count.toString()+' time(s)' ;
var img = new Image(1,1);
img.src = 'keepalive.aspx';
}
}
window.setInterval('Reconnect()'," + int_MilliSecondsTimeOut.ToString() + @"); //Set to length required
</script>
";
ClientScript.RegisterStartupScript(typeof(String), "Reconnect", str_Script, false);
}
private void AddPlayerScript()
{
//Insert script to the client to play the VLC Plugin
int int_MilliSecondsTimeOut = (Session.Timeout * 60000) - 30000;
string options = "";
string str_Script = "";
VLCCommon VLC = new VLCCommon(vlcProfile);
if (VLC.strmPlayer == "vlc")
{
if (Request.ServerVariables["HTTP_USER_AGENT"].IndexOf("MSIE") > 0)
{
str_Script = @"
<script>
window.status = 'Play Stream Activated'
function playVideo()
{
var options = new Array('http-caching=";
str_Script += VLC.strmBuffer;
str_Script += @"');
";
string location = "document.video1.addTarget('http://" + serverAddr + "', options , 4+8, -666);";
str_Script += location;
str_Script += @"
window.status = 'Play Button Clicked';
document.video1.play();
}
</script>
";
}
else
{
str_Script = @"
<script>
function playVideo()
{
document.video1.play();
}
</script>
";
}
}
ClientScript.RegisterStartupScript(typeof(String), "playVideo", str_Script, false);
}
protected void streamButton_Click(object sender, EventArgs e)
{
MusicVideoControls.Visible = true;
playerOptions.Visible = false;
transcodeOptions.Visible = false;
settingsButtons.Visible = false;
pluginArea.Visible = false;
VLCCommon VLC = new VLCCommon(vlcProfile);
if (VLC.strmPlayer == "dnld")
{
launchPlayer.Text = "Launch Download";
}
else
{
if (VLC.strmExternal)
{
launchPlayer.Text = "Launch External Player";
}
else
{
launchPlayer.Text = "Launch Plugin";
}
}
if (Request.Params["type"] == null)
{
if (vlcProfile == 1)
{
SETTINGS_HEADER.InnerHtml = "Streamer Controls - Video Library";
}
else
{
SETTINGS_HEADER.InnerHtml = "Streamer Controls - Music Library";
}
}
else
{
if (Request.Params["type"] == "sn")
{
SETTINGS_HEADER.InnerHtml = "Streamer Controls - Stream Now";
}
else
{
SETTINGS_HEADER.InnerHtml = "Streamer Controls - Manage Recordings";
}
}
if (((Request.Params["mvid"] != null) && (Request.Params["mvid"].Length != 0)) ||
((Request.Params["mid"] != null) && (Request.Params["mid"].Length != 0)) ||
((Request.Params["type"] != null) && (Request.Params["type"].Length != 0)))
{
AddKeepAlive();
doPlay();
}
}
protected void resetButton_Click(object sender, EventArgs e)
{
//Load settings
guideParams = Global.Settings;
//Instantiate a VLC instance defaulted to correct profile
VLCCommon VLC = new VLCCommon(vlcProfile);
//Web Streamer VLC Common Class
streamPlayer.Text = VLC.getPlayer();
//Need to set the appropriate pre-configed options on the page based on player selection
streamPlayer_SelectedIndexChanged(null, null);
externalPlayer.Checked = VLC.strmExternal;
streamPort.Text = VLC.getStrmPort().ToString();
streamBuffer.Text = VLC.getStrmBuffer().ToString();
streamPriority.Text = VLC.getStrmPriority();
streamBitRate.Text = VLC.getStrmBitRate().ToString();
streamVideoSizeOpt.SelectedValue = VLC.getStrmVideoSizeOpt();
if (streamVideoSizeOpt.SelectedValue == "preset")
{
streamVideoScaleSize.Visible = false;
streamVideoSize.Visible = true;
}
else
{
streamVideoSizeOpt.SelectedValue = "scale";
streamVideoSize.Visible = false;
streamVideoScaleSize.Visible = true;
}
streamVideoSize.Text = VLC.getStrmVideoSize();
streamVideoScaleSize.Text = VLC.getStrmVideoScale();
streamSetting.SelectedValue = VLC.getStrmSetting();
if (VLC.getStrmSetting() == "manual")
{
preConfigMessage.Visible = false;
manualOptions.Visible = true;
strmMux.SelectedValue = VLC.getStrmMux();
strmVideo.SelectedValue = VLC.getStrmVideo();
strmAudio.SelectedValue = VLC.getStrmAudio();
strmAudoBitrate.SelectedValue = VLC.getStrmAudioBitRate();
strmAudioChannels.SelectedValue = VLC.getStrmAudioChannels();
strmVencoder.SelectedValue = VLC.getStrmVEncoder();
if (VLC.getStrmVEncoder() == "h264")
{
H264.Visible = true;
//Web Streamer H264 Video Encoder Class. Instantiate to appropriate profile
H264Encoder H264Enc = new H264Encoder(vlcProfile);
strmH264KeyInt.Text = H264Enc.getH264KeyInt();
strmH264IDRInt.Text = H264Enc.getH264IDRInt();
strmH264BFrames.Text = H264Enc.getH264BFrames();
strmH264QuantizerParam.Text = H264Enc.getH264QuantizerParam();
strmH264QuantizerMax.Text = H264Enc.getH264QuantizerMax();
strmH264QuantizerMin.Text = H264Enc.getH264QuantizerMin();
strmH264CABAC.Checked = H264Enc.getH264CABAC();
strmH264LoopFilter.Checked = H264Enc.getH264LoopFilter();
strmH264Analyse.Checked = H264Enc.getH264Analyse();
strmH264FrameRef.Text = H264Enc.getH264FrameRef();
strmH264Adapt.Text = H264Enc.getH264Adapt();
strmH264Me.Text = H264Enc.getH264Me();
strmH264SubME.Text = H264Enc.getH264SubME();
strmH264ChromaME.Text = H264Enc.getH264ChromaME();
strmH264MERange.Text = H264Enc.getH264MERange();
}
else
{
H264.Visible = false;
}
}
else
{
preConfigMessage.Visible = true;
manualOptions.Visible = false;
H264.Visible = false;
}
}
private int GetVlcProfile()
{
//Determine if VLC object should be defualted to profile 1(video) or 2(audio)
if (Request.Params["playerType"] != null)
{
vlcProfile = Convert.ToInt16(Request.Params["playerType"]);
}
else
{
vlcProfile = 1;
}
return vlcProfile;
}
protected void playerOptsButton_Click(object sender, EventArgs e)
{
playerOptions.Visible = true;
if (Request.Params["type"] == null)
{
if (vlcProfile == 1)
{
SETTINGS_HEADER.InnerHtml = "Player Options - Video Library";
}
else
{
SETTINGS_HEADER.InnerHtml = "Player Options - Music Library";
}
}
else
{
if (Request.Params["type"] == "sn")
{
SETTINGS_HEADER.InnerHtml = "Player Options - Stream Now";
}
else
{
SETTINGS_HEADER.InnerHtml = "Player Options - Manage Recordings";
}
}
transcodeOptions.Visible = false;
MusicVideoControls.Visible = false;
hlSubmit_Click(null, null);
resetButton_Click(null, null);
}
protected void transOptsButton_Click(object sender, EventArgs e)
{
playerOptions.Visible = false;
MusicVideoControls.Visible = false;
transcodeOptions.Visible = true;
if (Request.Params["type"] == null)
{
if (vlcProfile == 1)
{
SETTINGS_HEADER.InnerHtml = "Transcode Options - Video Library";
}
else
{
SETTINGS_HEADER.InnerHtml = "Transcode Options - Music Library";
}
}
else
{
if (Request.Params["type"] == "sn")
{
SETTINGS_HEADER.InnerHtml = "Transcode Options - Stream Now";
}
else
{
SETTINGS_HEADER.InnerHtml = "Transcode Options - Manage Recordings";
}
}
if (streamSetting.SelectedValue != "manual")
{
manualOptions.Visible = false;
}
else
{
manualOptions.Visible = true;
}
hlSubmit_Click(null, null);
resetButton_Click(null, null);
}
protected void hlSubmit_Click(object sender, EventArgs e)
{
guideParams = Global.Settings;
//Determine correct VLC Profile
vlcProfile = GetVlcProfile();
if (vlcProfile != 2)
{
guideParams.strmPlayer = streamPlayer.Text;
guideParams.strmExternal = externalPlayer.Checked;
guideParams.strmPort = Convert.ToInt32(streamPort.Text);
guideParams.strmBuffer = Convert.ToInt32(streamBuffer.Text);
guideParams.strmPriority = streamPriority.Text;
guideParams.strmBitRate = Convert.ToInt32(streamBitRate.Text);
guideParams.strmVideoSizeOpt = streamVideoSizeOpt.Text;
guideParams.strmVideoSize = streamVideoSize.Text;
CultureInfo culture = new CultureInfo("en-US");
guideParams.strmVideoScaleSize =
String.Format("{0:00.00}",
decimal.Parse(streamVideoScaleSize.Text.Replace(',', '.'),
NumberStyles.AllowDecimalPoint, culture)).Replace(
',', '.');
streamVideoScaleSize.Text = guideParams.strmVideoScaleSize;
if (streamVideoSizeOpt.SelectedValue == "preset")
{
streamVideoScaleSize.Visible = false;
streamVideoSize.Visible = true;
}
else
{
streamVideoSize.Visible = false;
streamVideoScaleSize.Visible = true;
}
guideParams.strmSetting = streamSetting.Text;
if (streamSetting.Text == "manual")
{
preConfigMessage.Visible = false;
manualOptions.Visible = true;
guideParams.strmMux = strmMux.SelectedValue;
guideParams.strmVideo = strmVideo.SelectedValue;
guideParams.strmAudio = strmAudio.SelectedValue;
guideParams.strmAudoBitrate = strmAudoBitrate.SelectedValue;
guideParams.strmAudioChannels = strmAudioChannels.SelectedValue;
guideParams.strmVEncoder = strmVencoder.SelectedValue;
if (strmVencoder.SelectedValue == "h264")
{
H264.Visible = true;
guideParams.strmH264KeyInt = strmH264KeyInt.Text;
guideParams.strmH264IDRInt = strmH264IDRInt.Text;
guideParams.strmH264BFrames = strmH264BFrames.Text;
guideParams.strmH264QuantizerParam = strmH264QuantizerParam.Text;
guideParams.strmH264QuantizerMax = strmH264QuantizerMax.Text;
guideParams.strmH264QuantizerMin = strmH264QuantizerMin.Text;
guideParams.strmH264CABAC = strmH264CABAC.Checked;
guideParams.strmH264LoopFilter = strmH264LoopFilter.Checked;
guideParams.strmH264Analyse = strmH264Analyse.Checked;
guideParams.strmH264FrameRef = strmH264FrameRef.Text;
guideParams.strmH264Adapt = strmH264Adapt.Text;
guideParams.strmH264Me = strmH264Me.Text;
guideParams.strmH264SubME = strmH264SubME.Text;
guideParams.strmH264ChromaME = strmH264ChromaME.Text;
guideParams.strmH264MERange = strmH264MERange.Text;
}
else
{
H264.Visible = false;
}
}
else
{
preConfigMessage.Visible = true;
manualOptions.Visible = false;
H264.Visible = false;
}
}
else
{
guideParams.strmPlayer2 = streamPlayer.Text;
guideParams.strmExternal2 = externalPlayer.Checked;
guideParams.strmPort2 = Convert.ToInt32(streamPort.Text);
guideParams.strmBuffer2 = Convert.ToInt32(streamBuffer.Text);
guideParams.strmPriority2 = streamPriority.Text;
guideParams.strmBitRate2 = Convert.ToInt32(streamBitRate.Text);
guideParams.strmVideoSizeOpt2 = streamVideoSizeOpt.Text;
guideParams.strmVideoSize2 = streamVideoSize.Text;
CultureInfo culture = new CultureInfo("en-US");
guideParams.strmVideoScaleSize2 =
String.Format("{0:00.00}",
decimal.Parse(streamVideoScaleSize.Text.Replace(',', '.'),
NumberStyles.AllowDecimalPoint, culture)).Replace(
',', '.');
streamVideoScaleSize.Text = guideParams.strmVideoScaleSize2;
if (streamVideoSizeOpt.SelectedValue == "preset")
{
streamVideoScaleSize.Visible = false;
streamVideoSize.Visible = true;
}
else
{
streamVideoSize.Visible = false;
streamVideoScaleSize.Visible = true;
}
guideParams.strmSetting2 = streamSetting.Text;
if (streamSetting.Text == "manual")
{
preConfigMessage.Visible = false;
manualOptions.Visible = true;
guideParams.strmMux2 = strmMux.SelectedValue;
guideParams.strmVideo2 = strmVideo.SelectedValue;
guideParams.strmAudio2 = strmAudio.SelectedValue;
guideParams.strmAudoBitrate2 = strmAudoBitrate.SelectedValue;
guideParams.strmAudioChannels2 = strmAudioChannels.SelectedValue;
guideParams.strmVEncoder2 = strmVencoder.SelectedValue;
if (strmVencoder.SelectedValue == "h264")
{
H264.Visible = true;
guideParams.strmH264KeyInt2 = strmH264KeyInt.Text;
guideParams.strmH264IDRInt2 = strmH264IDRInt.Text;
guideParams.strmH264BFrames2 = strmH264BFrames.Text;
guideParams.strmH264QuantizerParam2 = strmH264QuantizerParam.Text;
guideParams.strmH264QuantizerMax2 = strmH264QuantizerMax.Text;
guideParams.strmH264QuantizerMin2 = strmH264QuantizerMin.Text;
guideParams.strmH264CABAC2 = strmH264CABAC.Checked;
guideParams.strmH264LoopFilter2 = strmH264LoopFilter.Checked;
guideParams.strmH264Analyse2 = strmH264Analyse.Checked;
guideParams.strmH264FrameRef2 = strmH264FrameRef.Text;
guideParams.strmH264Adapt2 = strmH264Adapt.Text;
guideParams.strmH264Me2 = strmH264Me.Text;
guideParams.strmH264SubME2 = strmH264SubME.Text;
guideParams.strmH264ChromaME2 = strmH264ChromaME.Text;
guideParams.strmH264MERange2 = strmH264MERange.Text;
}
else
{
H264.Visible = false;
}
}
else
{
preConfigMessage.Visible = true;
manualOptions.Visible = false;
H264.Visible = false;
}
}
Global.Settings.Save();
}
private void getTheme()
{
string theme = Convert.ToString(Session["theme"]);
if (theme != null && theme != "")
{
return;
}
else
{
HttpCookie cookie = Request.Cookies["theme"];
if (cookie != null && cookie.Value.Length > 0)
{
theme = cookie.Value;
}
else
{
theme = "Default";
}
Session["theme"] = "themes/" + theme;
return;
}
}
protected void streamPlayer_SelectedIndexChanged(object sender, EventArgs e)
{
if (IsPostBack)
{
if (streamPlayer.SelectedValue == "dnld")
{
string holdSelection = streamSetting.SelectedValue;
setDownloadTransOptions();
try
{
streamSetting.SelectedValue = holdSelection;
}
catch
{
streamSetting.Items[0].Selected = true;
}
hlSubmit_Click(null, null);
}
else
{
string holdSelection = streamSetting.SelectedValue;
setNonDownloadTransOptions();
try
{
streamSetting.SelectedValue = holdSelection;
}
catch
{
streamSetting.Items[0].Selected = true;
}
hlSubmit_Click(null, null);
}
}
}
private void setDownloadTransOptions()
{
streamSetting.Items.Clear();
streamSetting.Items.Add("MP4V/MPGA/MPEG-TS");
streamSetting.Items[0].Value = "dvs0";
streamSetting.Items[0].Selected = true;
streamSetting.Items.Add("MP2V/MPGA/MPEG-TS");
streamSetting.Items[1].Value = "dvs1";
streamSetting.Items.Add("MP1V/MPGA/MPEG-TS");
streamSetting.Items[2].Value = "dvs2";
streamSetting.Items.Add("Manual Options");
streamSetting.Items[3].Value = "manual";
}
private void setNonDownloadTransOptions()
{
streamSetting.Items.Clear();
streamSetting.Items.Add("MP4V/MP4A/MPEG-TS");
streamSetting.Items[0].Value = "0";
streamSetting.Items.Add("WMV/MP4A/MPEG-TS");
streamSetting.Items[1].Value = "1";
streamSetting.Items.Add("WMV/MP3/ASF");
streamSetting.Items[2].Value = "2";
streamSetting.Items.Add("H264/MP4A/MPEG-TS");
streamSetting.Items[3].Value = "3";
streamSetting.Items.Add("Manual Options");
streamSetting.Items[4].Value = "manual";
}
protected void externalPlayer_CheckedChanged(object sender, EventArgs e)
{
if (IsPostBack)
{
hlSubmit_Click(null, null);
resetButton_Click(null, null);
}
}
private string GetFilename()
{
//Setup schedule to obtain program info to stream
Schedule scheduleHelper = Global.Schedule;
string filename = "";
//Search/pull the filename of the passed recording
if (Request.Params["rid"] != null)
{
ScheduledRecording scheduledRecording = scheduleHelper.GetScheduledRecordingByOID(Convert.ToInt32(Request.Params["rid"]));
if (scheduledRecording != null)
{
filename = scheduledRecording.getFileName();
}
}
else
{
//We are accessing either a Music of Video Library item
if (Request.Params["mvid"] != null)
{
string path = (string)PublicDownload.Deseralize(Request.Params["mvid"]);
filename = Library.GetRealPath(path);
Logger.Info("***********************");
Logger.Info("File Name Deserialized: " + filename);
}
else
{
//We are accessing an entire directory of music or videos
if (Request.Params["mid"] != null)
{
string path = (string)PublicDownload.Deseralize((string)Request.Params["mid"]);
string tmpDir = Environment.GetEnvironmentVariable("ALLUSERSPROFILE");
filename = Path.Combine(tmpDir, Download.streamLibraryFolder(Request, path));
Logger.Info("***********************");
Logger.Info("File Location Deserialized: " + filename);
}
}
}
return filename;
}
protected void launchPlayer_Click(object sender, System.EventArgs e)
{
//Set the parameter variables for the plugin players
string vsize;
if (vlcProfile == 1)
{
vsize = guideParams.strmVideoSize;
}
else
{
vsize = guideParams.strmVideoSize2;
}
VLCCommon VLC = new VLCCommon(vlcProfile);
string width = " WIDTH=\"320\"";
string heigth = " HEIGHTH=\"213\"";
EMBEDDED_PLAYER.InnerHtml = "";
getServerAddress();
if (VLC.strmPlayer != "dnld")
{
if ((vlcProfile == 1 && !guideParams.strmExternal) || (vlcProfile == 2 && !guideParams.strmExternal2))
{
pluginArea.Visible = true;
launchPlugin(width, heigth);
}
else
{
pluginArea.Visible = false;
//Launch VLC External player
if ((vlcProfile == 1 && guideParams.strmPlayer == "vlc") ||
(vlcProfile == 2 && guideParams.strmPlayer2 == "vlc"))
{
Response.AddHeader("Content-Type", "video/mpeg4");
Response.AddHeader("Content-Disposition", "attachment; filename=\"stream.vlc\"");
Response.Write("#EXTM3U\r\n");
Response.Write("http://" + getServerAddress() + "\n");
Response.End();
}
else
//Launch Windows Media Player (as long as ASF is associated to Windows Media)
{
Response.AddHeader("Content-Type", "video/x-ms-asf");
Response.AddHeader("Content-Disposition", "attachment; filename=\"stream.asx\"");
Response.Write("http://" + getServerAddress() + "\n");
Response.End();
}
}
}
else
{
Response.AddHeader("Content-Type", "text/plain");
string filename = GetFilename();
Response.AddHeader("Content-Disposition", "attachment; filename=\"download_stream.bat\"");
string dnldFile = " --sout file/raw:\"%HOMEDRIVE%%HOMEPATH%\\" + filename.Substring(filename.LastIndexOf("\\") + 1, ((filename.Length - 1) - filename.LastIndexOf("\\")));
//set file extension of downloaded file based on profile
switch (vlcProfile)
{
//Profile 1 is the video profile
case 1:
switch (streamSetting.SelectedValue)
{
case "0":
dnldFile += ".mpg\"";
break;
case "1":
dnldFile += ".wmv\"";
break;
case "2":
dnldFile += ".wmv\"";
break;
case "3":
dnldFile += ".mpg\"";
break;
case "manual":
switch (VLC.strmVideo)
{
case "WMV1":
dnldFile += ".wmv\"";
break;
case "WMV2":
dnldFile += ".wmv\"";
break;
default:
dnldFile += ".mpg\"";
break;
}
break;
default:
dnldFile += ".mpg\"";
break;
}
break;
//Profile 2 is the audio profile
case 2:
switch (streamSetting.SelectedValue)
{
//since all the pre-config settings result in .mpg extension we only need to look at
//the manaul setting
case "manual":
switch (VLC.strmAudio)
{
case "mp4a":
dnldFile += ".mp4\"";
break;
case "mp3":
dnldFile += ".mp3\"";
break;
default:
dnldFile += ".mpg\"";
break;
}
break;
default:
dnldFile += ".mpg\"";
break;
}
break;
//Catch all.....we will handle the file as Profile 1 (video)
default:
switch (streamSetting.SelectedValue)
{
case "0":
dnldFile += ".mpg\"";
break;
case "1":
dnldFile += ".wmv\"";
break;
case "2":
dnldFile += ".wmv\"";
break;
case "3":
dnldFile += ".mpg\"";
break;
case "manual":
switch (VLC.strmVideo)
{
case "WMV1":
dnldFile += ".wmv\"";
break;
case "WMV2":
dnldFile += ".wmv\"";
break;
default:
dnldFile += ".mpg\"";
break;
}
break;
default:
dnldFile += ".mpg\"";
break;
}
break;
}
//Response.Write("\"" + VLC.getVLCLoc() + "vlc.exe\" " + "http://" + serverAddr + " --sout file/raw:\"" + filename.Substring(filename.LastIndexOf("\\") + 1, ((filename.Length - 1) - filename.LastIndexOf("\\"))) + ".mpg\"");
Response.Write("\"" + VLC.getVLCLoc() + "vlc.exe\" " + "http://" + serverAddr + dnldFile);
Response.End();
}
}
private void launchPlugin(string width, string heigth)
{
//Windows Media Plugin
if ((vlcProfile == 1 && guideParams.strmPlayer == "wmp") || (vlcProfile != 1 && guideParams.strmPlayer2 == "wmp"))
{
//Media Player for non IE browser
if (Request.ServerVariables["HTTP_USER_AGENT"].IndexOf("MSIE") < 1)
{
EMBEDDED_PLAYER.InnerHtml = " <EMBED TYPE=\"application/x-mplayer2\"";
EMBEDDED_PLAYER.InnerHtml += " AutoStart=\"true\"";
EMBEDDED_PLAYER.InnerHtml += " NAME=\"video1\"";
EMBEDDED_PLAYER.InnerHtml += " ShowControls=\"1\" ShowStatusBar=\"1\" AutoSize=\"false\" loop=\"false\" EnableContextMenu=\"0\" DisplaySize=\"0\"";
EMBEDDED_PLAYER.InnerHtml += " SRC=\"http://" + getServerAddress() + "\"";
EMBEDDED_PLAYER.InnerHtml += width;
EMBEDDED_PLAYER.InnerHtml += heigth;
EMBEDDED_PLAYER.InnerHtml += " </EMBED>";
}
else
//Media Player for IE browser
{
EMBEDDED_PLAYER.InnerHtml = "<OBJECT id=\"VIDEO\" " + width + "\" " + heigth + "\"";
EMBEDDED_PLAYER.InnerHtml += " CLASSID=\"CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6\"";
EMBEDDED_PLAYER.InnerHtml += "type=\"application/x-oleobject\">\n";
EMBEDDED_PLAYER.InnerHtml += "<PARAM NAME=\"URL\" VALUE=\"http://" + getServerAddress() + "\">\n";
EMBEDDED_PLAYER.InnerHtml += "<PARAM NAME=\"AutoStart\" VALUE=\"True\">\n";
EMBEDDED_PLAYER.InnerHtml += "<PARAM name=\"uiMode\" value=\"mini\">\n";
EMBEDDED_PLAYER.InnerHtml += "</OBJECT>\n";
}
}
//VLC Plugin being displayed in IE
else if (Request.ServerVariables["HTTP_USER_AGENT"].IndexOf("MSIE") > 0)
{
EMBEDDED_PLAYER.InnerHtml += " <OBJECT id=\"video1\" codeBase=\"http://downloads.videolan.org/pub/videolan/vlc/latest/win32/axvlc.cab\" " + width + " " + heigth + " classid=\"clsid:E23FE9C6-778E-49D4-B537-38FCDE4887D8\" events=\"True\" >\n";
EMBEDDED_PLAYER.InnerHtml += " <PARAM NAME=\"AutoLoop\" VALUE=\"FALSE\">\n";
EMBEDDED_PLAYER.InnerHtml += " <PARAM NAME=\"AutoPlay\" VALUE=\"TRUE\">\n";
EMBEDDED_PLAYER.InnerHtml += " <PARAM NAME=\"MRL\" VALUE=\"\">";
EMBEDDED_PLAYER.InnerHtml += " <PARAM NAME=\"ShowDisplay\" VALUE=\"TRUE\">\n";
EMBEDDED_PLAYER.InnerHtml += " </OBJECT>\n";
//AddPlayerScript();
}
//VLC Plugin being displayed in a non-IE browser
else
{
EMBEDDED_PLAYER.InnerHtml += " <embed type=\"application/x-vlc-plugin\" name=\"video1\" autoplay=\"yes\" loop=\"no\" " + width + " " + heigth;
EMBEDDED_PLAYER.InnerHtml += " target=\"http://" + getServerAddress() + "\">";
//AddPlayerScript();
}
}
protected string getServerAddress()
{
serverAddr = string.Empty;
//Get the server IP
string serverIP = Request.ServerVariables["http_host"];
int index = serverIP.IndexOf(":");
if (index > -1)
serverIP = serverIP.Substring(0, index).Trim();
if ((serverIP == null) || (serverIP.Length < 1))
serverIP = getIP();
//Create the address the stream will be available on
serverAddr = serverIP + ":" + guideParams.strmPort;
return (serverAddr);
}
protected string getIP()
{
//Alternative method for obtaining external IP if it can not be obtained by Request.Servervariables
System.Net.WebClient wclient = new System.Net.WebClient();
wclient.DownloadFile("http://www.whatismyip.com/", Request.MapPath("ip.txt"));
FileStream FS = new FileStream(Request.MapPath("ip.txt"), FileMode.Open);
StreamReader SR = new StreamReader(FS);
string entirefile = SR.ReadToEnd();
int startIndex = entirefile.IndexOf("<h1>Your IP");
int endIndex = entirefile.IndexOf("</", startIndex);
string restOfTheLine = entirefile.Substring(startIndex + 15, (endIndex - startIndex - 15));
string theIp = restOfTheLine.TrimEnd("<>brh1 ".ToCharArray());
SR.Close();
FS.Close();
File.Delete(Request.MapPath("ip.txt"));
return theIp.Trim();
}
protected void doPlay()
{
//Process to launch VLC on server to stream video
//Setup schedule to obtain program info to stream
Schedule scheduleHelper = Global.Schedule;
string filename = GetFilename();
//Develop list of arguments to be passed to VLC on the server
string args;
//Instantiate a VLC instance defaulted to correct profile
VLCCommon VLC = new VLCCommon(vlcProfile);
if (VLC.getStrmSetting() == "manual")
{
if (VLC.getStrmVEncoder() == "h264")
{
//Instantiate H264 object to appropriate profile
H264Encoder H264Enc = new H264Encoder(vlcProfile);
args = VLC.genCommandLine(filename, VLC, H264Enc);
}
else
{
args = VLC.genCommandLine(filename, VLC);
}
}
else
{
args = VLC.genCommandLine(filename, VLC.getStrmSetting(), VLC.getStrmVideoSize(), VLC.getStrmMux(), VLC.getStrmBitRate(),
VLC.getStrmPort());
}
//Log what is being started on the server
Logger.Info("***********************");
if (vlcProfile == 1)
{
Logger.Info("VLC Path= " + guideParams.strmVLCLoc);
}
else
{
Logger.Info("VLC Path= " + guideParams.strmVLCLoc2);
}
Logger.Info("Args= " + args);
//Build the process that will run VLC on the server
psi = new System.Diagnostics.ProcessStartInfo(VLC.getVLCLoc() + "vlc.exe", args);
psi.UseShellExecute = false;
psi.RedirectStandardError = false;
psi.RedirectStandardInput = false;
psi.RedirectStandardOutput = false;
//Start the VLC process on the server
proc = System.Diagnostics.Process.Start(psi);
//Set the priority of the started process based off of user configuration
switch (VLC.getStrmPriority().ToUpper())
{
case "BELOWNORMAL":
proc.PriorityClass = System.Diagnostics.ProcessPriorityClass.BelowNormal;
break;
case "ABOVENORMAL":
proc.PriorityClass = System.Diagnostics.ProcessPriorityClass.AboveNormal;
break;
case "NORMAL":
proc.PriorityClass = System.Diagnostics.ProcessPriorityClass.Normal;
break;
case "HIGH":
proc.PriorityClass = System.Diagnostics.ProcessPriorityClass.High;
break;
default:
proc.PriorityClass = System.Diagnostics.ProcessPriorityClass.Normal;
break;
}
}
protected void killServerStream(object sender, EventArgs e)
{
killVLC();
pluginArea.Visible = false;
streamMessage.InnerHtml = "";
EMBEDDED_PLAYER.InnerHtml = "";
}
//Method that makes VLC on the server skip forward 10 seconds on the currently playing item
protected static void skipForwardStream(object sender, EventArgs e)
{
StreamerPost strmPost = new StreamerPost();
strmPost.Url = "http://localhost:8080/";
strmPost.PostItems.Add("seek_value", "+10sec");
strmPost.PostItems.Add("control", "seek");
strmPost.Type = StreamerPost.PostTypeEnum.Get;
string result = strmPost.Post();
result = String.Empty;
}
//Method that makes VLC on the server skip backward 10 seconds on the currently playing item
protected static void skipBackwardStream(object sender, EventArgs e)
{
StreamerPost strmPost = new StreamerPost();
strmPost.Url = "http://localhost:8080/";
strmPost.PostItems.Add("seek_value", "-10sec");
strmPost.PostItems.Add("control", "seek");
strmPost.Type = StreamerPost.PostTypeEnum.Get;
string result = strmPost.Post();
result = String.Empty;
}
//Method that makes VLC on the server skip to the next item in the playlist
protected static void nextStream(object sender, EventArgs e)
{
StreamerPost strmPost = new StreamerPost();
strmPost.Url = "http://localhost:8080/";
strmPost.PostItems.Add("control", "next");
strmPost.Type = StreamerPost.PostTypeEnum.Get;
string result = strmPost.Post();
result = String.Empty;
}
//Method that makes VLC on the server skip back to the previous item in the playlist
protected static void previousStream(object sender, EventArgs e)
{
StreamerPost strmPost = new StreamerPost();
strmPost.Url = "http://localhost:8080/";
strmPost.PostItems.Add("control", "previous");
strmPost.Type = StreamerPost.PostTypeEnum.Get;
string result = strmPost.Post();
result = String.Empty;
}
//Method that makes VLC on the server stop playing
protected static void stopStream(object sender, EventArgs e)
{
StreamerPost strmPost = new StreamerPost();
strmPost.Url = "http://localhost:8080/";
strmPost.PostItems.Add("control", "stop");
strmPost.Type = StreamerPost.PostTypeEnum.Get;
string result = strmPost.Post();
result = String.Empty;
}
//Method that makes VLC on the server start to play the playlist
protected static void playStream(object sender, EventArgs e)
{
StreamerPost strmPost = new StreamerPost();
strmPost.Url = "http://localhost:8080/";
strmPost.PostItems.Add("control", "play");
strmPost.Type = StreamerPost.PostTypeEnum.Get;
string result = strmPost.Post();
result = String.Empty;
}
//Method that makes VLC on the server pause playing of the currently playing item
protected static void pauseStream(object sender, EventArgs e)
{
StreamerPost strmPost = new StreamerPost();
strmPost.Url = "http://localhost:8080/";
strmPost.PostItems.Add("control", "pause");
strmPost.Type = StreamerPost.PostTypeEnum.Get;
string result = strmPost.Post();
result = String.Empty;
}
//Method that Kills the VLC process on the server
protected void stopStreamer(object sender, EventArgs e)
{
settingsButtons.Visible = true;
playerOptions.Visible = true;
if (Request.Params["type"] == null)
{
if (vlcProfile == 1)
{
SETTINGS_HEADER.InnerHtml = "Player Options - Video Library";
}
else
{
SETTINGS_HEADER.InnerHtml = "Player Options - Music Library";
}
}
else
{
if (Request.Params["type"] == "sn")
{
SETTINGS_HEADER.InnerHtml = "Player Options - Stream Now";
}
else
{
SETTINGS_HEADER.InnerHtml = "Player Options - Manage Recordings";
}
}
transcodeOptions.Visible = false;
MusicVideoControls.Visible = false;
//Kill the VLC process on the server
killVLC();
//If we were streaming via the Stream Now option we need to get rid of the recording
if (Request.Params["rid"] != null && Request.Params["type"] != null)
{
if (Request.Params["type"] == "sn")
{
Schedule scheduleHelper = Global.Schedule;
ScheduledRecording scheduledRecording = scheduleHelper.GetScheduledRecordingByOID(Convert.ToInt32(Request.Params["rid"]));
if (scheduledRecording != null)
{
scheduleHelper.CancelScheduledRecording(scheduledRecording);
scheduledRecording = scheduleHelper.GetScheduledRecordingByOID(Convert.ToInt32(Request.Params["rid"]));
scheduleHelper.CancelScheduledRecording(scheduledRecording);
}
}
}
}
protected static void killVLC()
{
// kill any existing VLC processes
try
{
foreach (System.Diagnostics.Process thisproc in System.Diagnostics.Process.GetProcessesByName("vlc"))
{
thisproc.Kill();
}
}
catch (Exception Exc)
{
}
}
}
}